import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '../public-path'
// 可以阻止 vue 在启动时生成生产提示
Vue.config.productionTip = false
Vue.use(ElementUI, {size: 'small'})

let instance = null

function render(props) {
  const {container} = props || {}
  instance =  new Vue({
    router,
    render: h => h(App),
  }).$mount(container ? container.querySelector('#sub-threejs') : '#sub-threejs') 
}

// 独立运行的时候
if(!window.__POWERED_BY_QIANKUN__){
  render()
}

export async function bootstrap() {
  console.log('vue2 子应用创建')
}

export async function mount(props){
  console.log('vue2 子应用加载')
  render(props)
}

export async function unmount(){
  console.log('vue2 子应用销毁')
  instance.$destroy()
  instance.$el.innerHtml = ''
  instance = null
}
